package ctgu.java;

import java.time.ZonedDateTime;

public class HoldingTimeByZoned {
   
    private ZonedDateTime startingTime; //开始通话时间
    private ZonedDateTime endingTime;   //结束通话时间

    public HoldingTimeByZoned(ZonedDateTime startingTime, ZonedDateTime endingTime) {
        this.startingTime = startingTime;
        this.endingTime = endingTime;
    }
    
    /**
     * 获取通话时间
     * 
     * @return
     */
    public long getHoldingTime() {
        long minute = 0;
        long between ;
        
        between = endingTime.toEpochSecond() - startingTime.toEpochSecond();
        
        if (between < 0)
            minute = between / 60;// 得到通话时长
        else
            minute = (between + 59) / 60;//不到一分钟，算一分钟
        
 
        if (minute > 1800 || minute < 0) {
            throw new RuntimeException("通话时间不正确");
        } else {
            return minute;
        }
    }
}

